package eatwatch;

import java.util.*;

public final class DatabaseInMemory implements IDatabase
{
	// member variables
	Hashtable	mTables 	= new Hashtable ();
	Vector		mCrtTable 	= null;
	int			mTableIdx   = -1;

	// public interface
	public void	Open (String table)
	{
		mCrtTable = (Vector) mTables.get (table);

		if (mCrtTable == null) {
			mCrtTable = new Vector ();
			mTables.put (table, mCrtTable);
		}
		mTableIdx = 0;
	}

	public void	Open (String table, String sortField)
	{
		throw new RuntimeException ("Not implemented!");
	}

	public Record  FindRecord (String field, Object value)
	{
		throw new RuntimeException ("Not implemented!");
	}

	public void Close ()
	{
	}

	public void AddRecord (Record record)
	{
		mCrtTable.addElement (record);
	}

	public Record ReadRecord ()
	{
		if (mTableIdx < mCrtTable.size ()) {
			Record record = (Record) mCrtTable.elementAt (mTableIdx);
			record.SetId (mTableIdx++);
			return record;
		}
		else
			return null;
	}

	public void UpdateRecord (Record record)
	{
		mCrtTable.setElementAt (record, record.GetId ());
	}

	public void DeleteRecord (int recordId)
	{
		mCrtTable.removeElementAt (recordId);
	}
	// helper classes
}